<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" >
<head>
    <meta charset="UTF-8">
    <title>发布新投票</title>
    <link rel="stylesheet" type="text/css" th:href="@{/mystatic/bootstrap-3.4.1-dist/css/bootstrap.css}" />
    <link rel="stylesheet" type="text/css" th:href="@{/mystatic/bootstrap-3.4.1-dist/css/bootstrap-theme.css}" />
    <script type="text/javascript"  th:src="@{/mystatic/js/jquery-1.8.3.js}"></script>
</head>
<body>
<h2 align="center" >发布新投票</h2>
<div class="container-fluid" >
    <div class="row">
        <div class="col-md-2"></div>
        <div class="col-md-8">
            <form class="form-horizontal" th:action="@{/adminsaveSubject}" method="post">
                <div class="form-group">
                    <label for="title" class="col-sm-2 control-label">投票内容</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="title" th:value="${session.sub != null}? ${session.sub.vs_title} : '' "  name="vs_title" placeholder="输入投票内容...">
                    </div>
                </div>
                <div class="form-group">
                    <label for="title" class="col-sm-2 control-label">投票类型</label>
                    <div class="radio">
                        <div class="col-sm-10">
                            <label>
                                <input type="radio" name="vs_type"  th:checked="${#session.getAttribute('sub') != null and #session.getAttribute('sub').vs_type eq 1 or #session.getAttribute('sub') eq null }"  id="blankRadio1" value="1" aria-label="..."> 单选
                            </label>
                            <label>
                                <input type="radio" name="vs_type" th:checked="${#session.getAttribute('sub') != null and  #session.getAttribute('sub').vs_type eq 2}"  id="blankRadio2" value="2" aria-label="..."> 多选
                            </label>
                        </div>
                    </div>
                </div>
                <div class="form-group" id="voteoptions">
                    <label for="optitle" class="col-sm-2 control-label">投票选项 </label>
                   <!-- <c:if test="${sessionScope.op != null}">
                        <c:forEach var="v" items="${sessionScope.op}" >-->
                       <span th:each="v:${session.op}">
                            <div  class="col-sm-10">
                                <input type="text" class="form-control" id="title" th:value="${v}"   name="op" placeholder="输入选项内容...">
                            </div>
                            <label   for="title" class="col-sm-2 control-label"> </label>
                        </span>
                   <!--     </c:forEach>
                    </c:if>-->
                    <!--<c:if test="${sessionScope.op == null}">-->

                        <div th:if="${session.op eq null}" class="col-sm-10">
                            <input type="text" class="form-control" id="title" name="op" placeholder="输入选项内容...">
                        </div>
                        <label th:if="${session.op eq null}"  for="title" class="col-sm-2 control-label"> </label>
                        <div th:if="${session.op eq null}"  class="col-sm-10">
                            <input type="text" class="form-control" id="title" name="op" placeholder="输入选项内容...">
                        </div>
                  <!--  </c:if>-->
                </div>
                <div class="form-group">
                    <label  class="col-sm-2 control-label">
                        &nbsp;
                    </label>
                    <label  class="col-sm-2 control-label">
                        <input type="submit" name="sub" class="btn btn-success btn-sm" value="发布投票" />
                    </label>
                    <label  class="col-sm-2 control-label">
                        <input type="button" name="btn" id="addOption" class="btn btn-info btn-sm" value="增加选项" />
                    </label>
                </div>
            </form>
        </div>
        <div class="col-md-2"></div>
    </div>
</div>
    <script  th:if="${session.saveerr != null}" type="text/javascript">
        alert("标题不能重复");
        [(${#session.removeAttribute('saveerr')})]
    </script>
    <!-- 删除回显状态op sub -->
    <!-- <c:remove var="op" scope="session" />-->
     [(${#session.removeAttribute('sub')})]
     [(${#session.removeAttribute('op')})]
<script type="text/javascript">
    $(function(){
        //alert("abc");
        $("#addOption").click(function(){
            var $p=$('<div ></div>');
            var $text=$('<label  class="col-sm-2 control-label" /> &nbsp; </label> <div class="col-sm-8"> <input type="text" class="form-control" name="op"  placeholder="输入选项内容..." /> </div>');
            var $del=$('<div class="col-sm-2"> <a href="javascript:void(0)" >删除</a></div> ');
            $del.click(function(){
                $(this).parent().remove();
            });
            $p.append($text).append($del);
            $("#voteoptions").append($p);
        });
    });
</script>
</body>

</html>
